import java.util.Arrays;

public class Solution1775 {
    public int minOperations(int[] nums1, int[] nums2) {
        if (Arrays.stream(nums1).sum()>Arrays.stream(nums2).sum()){
            int[] t=nums1;
            nums1=nums2;
            nums2=t;
        }
        int[] f=new int[7];
        int[] g=new int[7];
        for (int i : nums1) {
            f[i]++;
        }
        for (int i : nums2) {
            g[i]++;
        }
        int sub=Arrays.stream(nums2).sum()-Arrays.stream(nums1).sum();
        int ans=0;
        for (int i=1;i<6;i++){
            int l=sub%(6-i)==0?sub/(6-i):sub/(6-i)+1;
            if (l<=f[i]){
                ans+=l;
                return ans;
            }else {
                ans+=f[i];
                sub-=(6-i)*f[i];
            }
            l=sub%(6-i)==0?sub/(6-i):sub/(6-i)+1;
            if (l<=g[7-i]){
                ans+=l;
                return ans;
            }else {
                ans+=g[7-i];
                sub-=(6-i)*g[7-i];
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1775().minOperations(new int[]{1,2,3,4,5,6},new int[]{1,1,2,2,2,2}));
    }
}
